package test5.lupeng.jf.com.teamdemo.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import org.w3c.dom.Text;

import java.util.ArrayList;

import test5.lupeng.jf.com.teamdemo.R;
import test5.lupeng.jf.com.teamdemo.bean.response.ResponseMyMessage;

/**
 * Created by Administrator on 2017/7/31.
 */

public class MyMessageAdapter extends RecyclerView.Adapter {
    ArrayList<ResponseMyMessage.ResultBean> beans;

    class  ItemViewHolder extends  RecyclerView.ViewHolder{
        ImageView iv_messageType;

        TextView tv_title;
        TextView tv_content;
        TextView tv_data;

        public ItemViewHolder(View itemView) {
            super(itemView);
            iv_messageType = itemView.findViewById(R.id.iv_messageType);
            tv_title = itemView.findViewById(R.id.title);
            tv_content = itemView.findViewById(R.id.tv_content);
            tv_data = itemView.findViewById(R.id.tv_data);
        }
    }

    public MyMessageAdapter(ArrayList<ResponseMyMessage.ResultBean> beans) {
        this.beans = beans;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.mymessages_item, parent, false);
        ItemViewHolder holder=new ItemViewHolder(view);
        return holder;
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        ResponseMyMessage.ResultBean bean = beans.get(position);
        ItemViewHolder itemViewHolder= (ItemViewHolder) holder;
        itemViewHolder.tv_title.setText("有用户在文章【"+bean.getArticle().getTitle()+"】@你");
        itemViewHolder.tv_content.setText(bean.getContent());
        itemViewHolder.tv_data.setText(bean.getArticle().getTimestamp()+"");
        switch (bean.getArticle().getBlogType()) {
            case 1:
                itemViewHolder.iv_messageType.setImageResource(R.drawable.ic_reader);
                break;
            case 2:
                itemViewHolder.iv_messageType.setImageResource(R.drawable.ic_help);
                break;
            case 3:
                itemViewHolder.iv_messageType.setImageResource(R.drawable.ic_movie);
                break;

        }


    }

    @Override
    public int getItemCount() {
        return beans.size();
    }
}
